package huawei;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 模拟项目管理
 */
public class Q81 {

    public static class DirectNode {
        String directName; // 目录名称
        List<DirectNode> children;
        DirectNode parent;

        public DirectNode(DirectNode parent, String directName) {
            this.parent = parent;
            this.directName = directName;
            children = new ArrayList<>();
        }
    }

    public void createDirect(DirectNode parent, String name) {
        if (parent == null) {return;}

        boolean isExist = false; // 判断子文件夹是否存在
        for (DirectNode child : parent.children) {
            if (child.directName.equals(name)) {
                isExist = true;
                break;
            }
        }

        if (isExist) return; // 如果同名的文件夹已经存在，直接返回

        DirectNode newNode = new DirectNode(parent, name);
        parent.children.add(newNode);
    }

    // cd命令
    public DirectNode commendCd(DirectNode parent, String name) {
        if (parent == null) {return null;}

        if (name.equals("..")) {
            if (parent.parent == null) return parent; // 根路径不操作

            return parent.parent;
        } else {
            for (DirectNode child : parent.children) {
                if (child.directName.equals(name)) {
                    return child;
                }
            }
        }

        return parent;
    }

    // pwd 命令
    public String commentPwd(DirectNode node) {
        if (node == null) {return null;}

        StringBuilder sb = new StringBuilder();

        while (node != null) {
            if (node.parent != null) {
                sb.insert(0,node.directName + "/");
            } else {
                sb.insert(0, node.directName);
            }
            node = node.parent;
        }

        return sb.toString();
    }

    public DirectNode init() {
        return new DirectNode(null, "/");
    }

    public DirectNode exeCommend(DirectNode cur,  String command) {
        if (command == null || command.isEmpty()) return cur;
        if (command.contains("/")) return cur; // 不能包含 “/”

        if (command.startsWith("mkdir")) {
            String[] strings = command.split(" ");
            if (strings.length != 2) return cur;

            String dname = strings[1].trim();

            if (dname.isEmpty()) return cur;

            this.createDirect(cur, dname);
        }
        if (command.startsWith("cd")) {
            String[] strings = command.split(" ");
            if (strings.length != 2) return cur;

            String dname = strings[1].trim();

            if (dname.isEmpty()) return cur;

            return this.commendCd(cur, dname);
        }
        if (command.equals("pwd")) {
            System.out.println(this.commentPwd(cur));
        }

        return cur;
    }


    public static void main(String[] args) {
        Q81 q81 = new Q81();
        DirectNode root = q81.init();

        DirectNode work = root;

        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String command = sc.nextLine();
            work = q81.exeCommend(work, command);
        }


    }
}
